package com.xzer.xiaozhuoerinterface.service;

import com.xzer.xiaozhuoerinterface.entity.HttpResult;
import com.xzer.xiaozhuoerinterface.entity.PlatInfo;
import com.xzer.xiaozhuoerinterface.mapper.InfoMapper;
import org.springframework.stereotype.Service;

@Service
public class ThirdService {

    private final InfoMapper infoMapper;

    public ThirdService(InfoMapper infoMapper) {
        this.infoMapper = infoMapper;
    }

    public HttpResult thirdIdCardNumAndPlatType(String idCardNum, String platType) {
        HttpResult httpResult = new HttpResult();
        PlatInfo platInfo  = infoMapper.getCreditLimit(platType);
        if(platInfo == null){
            httpResult.setStatus(-3);
            httpResult.setMsg("this platType does not exist");
            httpResult.setData("");
            return httpResult;
        }
        Integer credit = infoMapper.getCreditRateByIdCardNum(idCardNum);
        if(credit == null){
            httpResult.setStatus(-2);
            httpResult.setMsg("this idCardNum does not exist");
            httpResult.setData("");
            return httpResult;
        }
        if(credit < platInfo.getLimit())
        {
            httpResult.setStatus(-1);
            httpResult.setMsg("this user's credit failed in the paltType credit line");
            httpResult.setData("Refuse");
            return httpResult;
        }
        httpResult.setStatus(0);
        httpResult.setMsg("this user's credit passed the paltType credit line");
        httpResult.setData("Allow");
        return httpResult;
    }

    public HttpResult thirdIdCardNumAndCreditLimit(String idCardNum, int creditLimit) {
        HttpResult httpResult = new HttpResult();
        Integer credit = infoMapper.getCreditRateByIdCardNum(idCardNum);
        if(credit == null){
            httpResult.setStatus(-2);
            httpResult.setMsg("this idCardNum does not exist");
            httpResult.setData("");
            return httpResult;
        }
        if(credit < creditLimit)
        {
            httpResult.setStatus(-1);
            httpResult.setMsg("this user's credit failed in the creditLimit");
            httpResult.setData("Refuse");
            return httpResult;
        }
        httpResult.setStatus(0);
        httpResult.setMsg("this user's credit passed the creditLimit");
        httpResult.setData("Allow");
        return httpResult;
    }
}
